<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="/manager/index::head">
</head>

<body>
    <!-- 导航栏 -->
    <ul class="layui-nav" th:replace="/manager/index::nav">
    </ul>

    <div>
        <div style="text-align: center;background-color: #4191C2;color: white;height: 150px;">
            <h1 style="padding: 50px">图书编辑</h1>
        </div>
        <!-- 新版 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <div style="margin: 100px;">
                    <form class="layui-form" lay-filter="testform2">
                        <input type="hidden" name="id" th:value="${book.id}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">书名</label>
                            <div class="layui-input-block">
                                <input type="text" name="bName" th:value="${book.bName}" required lay-verify="required"
                                    placeholder="请输入书名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">价格</label>
                            <div class="layui-input-block">
                                <input type="text" name="bPrice" th:value="${book.bPrice}" required
                                    lay-verify="required" placeholder="请输入价格" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">库存</label>
                            <div class="layui-input-block">
                                <input type="text" name="bSize" th:value="${book.bSize}" required lay-verify="required"
                                    placeholder="请输入库存" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">作者</label>
                            <div class="layui-input-block">
                                <input type="text" name="bAuthor" th:value="${book.bAuthor}" required
                                    lay-verify="required" placeholder="作者" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">出版社</label>
                            <div class="layui-input-block">
                                <input type="text" name="bPress" th:value="${book.bPress}" required
                                    lay-verify="required" placeholder="请输入出版社" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>


</body>
<script>
    layui.use(['layer'], function (args) {
        var layer = layui.layer;
        var form = layui.form;
        form.on('submit(formDemo)', function (data) {
            $.post("/book/update", data.field, function (data) {
                if (data.code === "200") {
                    layer.msg('修改成功');
                    setTimeout(() => {
                        window.location.href="/admin/index"
                    }, 1000);
                }
            })
            return false;
        });
    }); 
</script>

</html>